package org.ghost.akka.client;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import com.typesafe.config.ConfigFactory;
import org.ghost.akka.common.command.BaseCommand;
import org.ghost.akka.common.command.ICommandProcessHandler;

/**
 * Akka Client Actor System
 */
public class AkkaClientSystem implements ICommandProcessHandler {
    /**
     * 初始化本地角色系统
     */
    private ActorSystem actorSystem = ActorSystem.create(AkkaClientConfig.CLIENT_SYSTEM, ConfigFactory.load().getConfig(AkkaClientConfig.CLIENT_SYSTEM_CONFIG));

    @Override
    public void doProcess(BaseCommand cmd) {
        ActorRef taskSender = actorSystem.actorOf(Props.create(TaskSendActor.class));
        taskSender.tell(cmd, ActorRef.noSender());
    }

    public ActorSystem getContext() {
        return actorSystem;
    }
}
